package vn.allmobile.newsreader.adapters;

import java.util.List;

import vn.allmobile.newsreader.R;
import vn.allmobile.newsreader.data.Paper;
import vn.allmobile.newsreader.utils.ImageLoader;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class LibraryAdapter extends BaseAdapter {

	List<Paper> mListPapers;
	Context mContext;
	ImageLoader mImageLoader;

	public LibraryAdapter(Context context, List<Paper> listPaper) {
		this.mContext = context;
		this.mListPapers = listPaper;
		this.mImageLoader = new ImageLoader(mContext);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.mListPapers.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.mListPapers.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.librarypapers_item, null);
		}
		ImageView mImage = (ImageView) convertView
				.findViewById(R.id.librarypapers_image);
		this.mImageLoader.DisplayImage(this.mListPapers.get(position)
				.getImage(), mImage);
		return convertView;
	}

}
